Skip to content

Expose per-channel black level corrections via user_cblack parameter#278

Merged
letmaik merged 5 commits intomainfrom
copilot/support-per-channel-black-corrections
Jan 28, 2026
Merged

Expose per-channel black level corrections via user_cblack parameter#278
letmaik merged 5 commits intomainfrom
copilot/support-per-channel-black-corrections

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 27, 2026

The existing user_black parameter applies a single black level to all channels, causing color casts when correcting low-value noise. libraw supports per-channel corrections via user_cblack[4] but rawpy didn't expose it.

Changes

  • Added user_cblack parameter to Params.__init__() accepting a 4-element list for [R, G, B, G2] channels
  • Validation ensures exactly 4 values provided
  • Integration with libraw's user_cblack[4] array in apply_params()
  • Documentation clarifies that user_cblack values are offsets/corrections applied on top of user_black
  • Test coverage for parameter validation, postprocessing, and combined usage with user_black

Usage

import rawpy

with rawpy.imread('image.nef') as raw:
    # Per-channel corrections on top of base black level
    # Effective black levels: [110, 120, 130, 120]
    rgb = raw.postprocess(user_black=100, user_cblack=[10, 20, 30, 20])

Key behavior: user_cblack values are corrections/offsets applied on top of the base user_black value, not absolute black levels. This allows setting a common base black level with per-channel fine-tuning.

Pattern follows existing user_wb parameter. Backward compatible - defaults to [0, 0, 0, 0] when not specified.

Original prompt

This section details on the original issue you should resolve

<issue_title>Support per-channel black level corrections</issue_title>
<issue_description>To crop noise in low grayscale regions, I want to use 'user_black' to crop very low grayscale regions, but since I can only set one int value for 'user_black', I can't subtract a separate value for each color. As a result, it gives the image an awkward color.
Is there any method to provide separate 'user_black' for each color channel?</issue_description>

Comments on the Issue (you are @copilot in this section)

@letmaik libraw (which rawpy is built on) does support per-channel black level corrections via `user_cblack[4]`. So in principle this could be exposed as a new parameter in rawpy. Could you give an example of how you would determine the per-channel correction values that you would use in this case?

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for per-channel black level corrections Expose per-channel black level corrections via user_cblack parameter Jan 27, 2026
Copilot AI requested a review from letmaik January 27, 2026 23:19
…entation

Co-authored-by: letmaik <530988+letmaik@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 27, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from letmaik January 27, 2026 23:31
@letmaik letmaik marked this pull request as ready for review January 27, 2026 23:46
@letmaik letmaik merged commit 5fa29ff into main Jan 28, 2026
110 checks passed
@letmaik letmaik deleted the copilot/support-per-channel-black-corrections branch January 28, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support per-channel black level corrections

2 participants